class AutocompleteController < ActionController::Base
  def index
    @array = send(params[:method])
  end
  
  def find_users
    @labeling = {:id => "id", 
                 :label => Proc.new{|o| "#{o.gpn} #{o.firstname} #{o.lastname}"},
                 :value => Proc.new{|o| "#{o.gpn} #{o.firstname} #{o.lastname}"}}
                 
    User.find(:all, :conditions => ["gpn like ? or firstname like ? or lastname like ?", 
                                    "%#{params[:term]}%", 
                                    "%#{params[:term]}%",
                                    "%#{params[:term]}%"])
  end
  
  def find_jurisdictions
    @labeling = {:id => "id", 
                 :label => "name",
                 :value => "name"}
                 
    Jurisdiction.find(:all, :conditions => ["name like ?", "%#{params[:term]}%"])
  end
end
